package list;

/**
 * @version 1.0
 * 功能目的描述 ：用于     约瑟夫环模拟实现    ========>>>>>>>>>>>
 * @author： pang-yun
 * @date： 2021-07-26 20:51
 */

public class JosephusListDemo {
    public static void main(String[] args) {

    }

    class JosephusList {
        private Node first = null;
        private Node current = null;

        public void addNode(int nums) {
            if (nums < 1) {
                System.out.println("输入的参数有误,不能创建这种josephus环");
            }
            for (int i = 1; i <= nums; i++) {
                Node node = new Node(i);
                if (i == 1) {
                    first.next = first;
                    current = first;
                } else {
                    current.next = node;
                    node.next = first;
                    current = first;
                }
            }
        }

        public void showJosephusList() {
            if (first==null){
                System.out.println("链表为空");
                return;
            }
            Node current =first;
            while (true){
                System.out.printf("编号 %d 出列\n",current.number);
                if (first.next==first){break;}
                current=current.next;
            }


        }
    }


    class Node {
        public int number;
        public Node next;

        public Node(int number) {
            this.number = number;
        }
    }
}